# -*- conding:utf-8 -*-
import config
import public.dingding as dingding
from tencent_api.DescribeDomainNameList import describe_domain_name_list
from datetime import datetime, timedelta
import json

if __name__ == '__main__':
    send_content = 'tencent域名有效期监测：'
    now = datetime.now()
    for k in config.tencent_auth:
        print(k)
        domain_list = describe_domain_name_list(k['key'],k['id'])['DomainSet']
        for i in domain_list:
            domain_name = i['DomainName']
            domain_expiration_date = i['ExpirationDate']
            domain_expiration_datetime_obj = datetime.strptime(domain_expiration_date,"%Y-%m-%d")
            date_diff = domain_expiration_datetime_obj - now
            domain_expiration_day = date_diff.days
            if domain_expiration_day <= 100:
                send_content = send_content + '\n' + '域名：' +  str(domain_name) + '有效期：' + str(domain_expiration_day)
    dingding.run(send_content)